package cn.group01.git.controller;

import cn.group01.git.annotations.LogOperation;
import cn.group01.git.common.Operation;
import cn.group01.git.common.ResponseResult;
import cn.group01.git.dto.GoodsPageDTO;
import cn.group01.git.entity.Goods;
import cn.group01.git.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
/**
 * @description:
 * @author: 笪志林
 * @date: 2023/7/13 15:52
 **/
@RestController
@RequestMapping("goods")
public class GoodsController {
    @Autowired
    private GoodsService goodsService;

    @GetMapping("list")
    @LogOperation(description = Operation.SELECT,model = "商品库存模块")
    public ResponseResult getList(GoodsPageDTO goodsPageDTO){
        return goodsService.getList(goodsPageDTO);
    }

    @GetMapping("selectGoodsName")
    @LogOperation(description = Operation.OTHER,model = "商品库存模块")
    public List<Goods> selectGoodsName(){
        return goodsService.selectGoodsName();
    }

    @PostMapping("batch")
    @LogOperation(description = Operation.ADD,model = "商品批量导入")
    public ResponseResult addGoods(MultipartFile file){
        return goodsService.batchAdd(file);
    }

    @GetMapping("export")
    @LogOperation(description = Operation.OTHER,model = "商品批量导出")
    public void export(String supName, HttpServletResponse response){
        goodsService.export(supName,response);
    }

    @GetMapping("delete")
    @LogOperation(description = Operation.DELETE,model = "商品库存模块")
    public ResponseResult batchdelete(Integer[] ids){
        return goodsService.batchDelete(ids);
    }

    @PostMapping("edit")
    @LogOperation(description = Operation.UPDATE,model = "商品库存模块")
    public ResponseResult editGoods(@RequestBody Goods goods){
        return goodsService.editGoods(goods);
    }

    @GetMapping("getByGoodsName")
    @LogOperation(description = Operation.SELECT,model = "商品库存模块")
    public Goods getByGoodsname(String goodsName){
        return goodsService.getByGoodsName(goodsName);
    }

    @PostMapping("add")
    @LogOperation(description = Operation.ADD,model = "商品库存模块")
    public ResponseResult addGoods(@RequestBody Goods goods){
        return goodsService.addGoods(goods);
    }


}
